package controller.business.managerAssess;

import com.lowagie.text.*;
import com.lowagie.text.rtf.RtfWriter2;
import itext.ItextFont;
import wt.entity.business.ManagerAssess;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Map;
import java.util.List;


public class ManagerAssessDoc {
    
    private static  List<Cell>  printContent(List<ManagerAssess> list) throws   DocumentException, IOException  {

        Map<ManagerAssess, List<ManagerAssess>> managerAssessListMap = ManagerAssessPdf.managerAssesList2Map(list);
        List<Cell>  cells = new ArrayList<Cell>();

        int u = 0;
        for (Map.Entry<ManagerAssess, List<ManagerAssess>> assessListEntry : managerAssessListMap.entrySet()) {
            u++;
            int size = assessListEntry.getValue().size();

            Cell cell=  new Cell(new Phrase(u+"", ItextFont.fangSongNormalDoc10));
            cell.setRowspan(size);
            cells.add(cell);
            cell=  new Cell(new Phrase(assessListEntry.getKey().getAccessTypeName(), ItextFont.fangSongNormalDoc10));
            cell.setRowspan(size);
            cells.add(cell);

            for (int i = 0; i < size; i++) {
                cell=  new Cell(new Phrase((i + 1)+"", ItextFont.fangSongNormalDoc10));
                cells.add(cell);
                cell=  new Cell(new Phrase(assessListEntry.getValue().get(i).getAccessTypeName(), ItextFont.fangSongNormalDoc10));
                cells.add(cell);
                cell = new Cell(new Phrase(assessListEntry.getValue().get(i).getResult(), ItextFont.fangSongNormalDoc10));

                cells.add(cell);
            }
        }
        return cells;
    }






    public static void createDoc(OutputStream outputStream,List<ManagerAssess> list) throws DocumentException, IOException {
        //设置纸张大小
        Document document = new Document(PageSize.A4);
        //建立一个书写器，与document对象关联
        RtfWriter2.getInstance(document, outputStream);
        document.open();

        Paragraph paragraph = new Paragraph("申报材料质量审核评价记录及审核意见", ItextFont.fangZhengDoc18);
        paragraph.setAlignment(Element.ALIGN_CENTER);
//        paragraph.setSpacingBefore(20f);
        document.add(paragraph);


        //设置Table表格,创建一个7列的表格
        Table table = new Table(5);
        float width[] = {1.1F,2.1F, 1, 10, 2};//设置每列宽度比例
        table.setWidths(width);
        table.setWidth(100);//占页面宽度比例
        table.setAlignment(Element.ALIGN_CENTER);//居中
        table.setAlignment(Element.ALIGN_MIDDLE);//垂直居中
        table.setAutoFillEmptyCells(true);//自动填满
        table.setBorderWidth(1);//边框宽度
        table.setPadding(12F);


        Cell[] cell = new Cell[6];
        cell[0] = new Cell(new Phrase("序号", ItextFont.fangSongBoldDoc10));

        cell[1] = new Cell(new Phrase("材料名称", ItextFont.fangSongBoldDoc10));
        cell[2] = new Cell(new Phrase("评价内容（不得出现以下情况）", ItextFont.fangSongBoldDoc10));
        cell[2].setColspan(2);
        cell[3] = new Cell(new Phrase("评价记录", ItextFont.fangSongBoldDoc10));

        for (int i = 0; i <4; i++) {
            cell[i].setHorizontalAlignment(Element.ALIGN_CENTER);//居中显示
            cell[i].setVerticalAlignment(Element.ALIGN_MIDDLE);//纵向居中显示
            table.addCell(cell[i]);
        }

        List<Cell>  Cells= printContent(list);

        for(Cell Cell:Cells){
            Cell.setHorizontalAlignment(Element.ALIGN_CENTER);//居中显示
            Cell.setVerticalAlignment(Element.ALIGN_MIDDLE);//纵向居中显示
            table.addCell(Cell);
        }

        paragraph = new Paragraph();
        paragraph.setSpacingBefore(5f);
        paragraph.add(table);
        document.add(paragraph);

        paragraph = new Paragraph("审核人：               日期：                审查组织单位（加盖公章）：" +
                "\n说明：“评价记录”栏填写“Y”（通过），“N”（不通过），“—”（不适用）。", ItextFont.fangSongNormalDoc10);
        paragraph.setSpacingBefore(3f);
        document.add(paragraph);
        document.close();

    }


}

